package com.api.hg.action;

import com.alibaba.fastjson.JSONObject;
import com.api.hg.model.uf_bmzcpdrw;
import com.api.hg.model.uf_grzcpdjl;
import com.api.hg.model.uf_kszcpdrw;
import com.api.hg.model.uf_zcpdrwxf;
import com.api.hg.service.Uf_bmzcpdrwBaseService;
import com.api.hg.service.Uf_zcpdrwxfBaseService;
import com.api.hg.service.uf_grzcpdjlBaseService;
import com.api.hg.service.uf_kszcpdrwBaseService;
import com.api.sw.duban.util.LogTool;
import com.cloudstore.eccom.constant.WeaBoolAttr;
import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.pc.table.WeaTableType;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.PageIdConst;
import weaver.hrm.User;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 资产盘点相关操作方法
 *
 */
public class assetDiscovery {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/assetDiscovery",false);
    //盘点  资产管理员de  界面
    //实物的：hth 合同号，pp 品牌(浏览单选)，ggxh规格型号(浏览单选)，sblx设备类型(浏览单选)，sbzt设备状态(公共选择框)
    public Map<String, Object> getTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String) weaver.general.Util.null2String(params.get("sbzt")) ;//设备状态
            String rq=(String) weaver.general.Util.null2String(params.get("rq")) ;//入库日期
            String dybm=(String) weaver.general.Util.null2String(params.get("bm")) ;//所在单位
            String year=(String) weaver.general.Util.null2String(params.get("year")) ;//盘点年度
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a423-81a4-7b7c6f7928571111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            String sqlwhere =" 1=1 and a.zczt in (0,1,3,4,5,6) and isnull(a.dybm,-1)>0 and isnull(a.syks,-1)>0 and isnull(a.zrr,-1)>0 ";

            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(dybm)){
                sqlwhere=sqlwhere+" and a.dybm in ("+sbzt+")";
            }
            if(!"".equals(year)){
                sqlwhere=sqlwhere+"  and not exists (select 1 from uf_grzcpdjl b where b.pdnf='"+year+"' and b.swzcid=a.id and isnull(b.sfyx,-1) in (-1,0) ) ";
            }else{
                sqlwhere=sqlwhere+" and 1=2";
            }

            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            assetAction assetAction=new assetAction();
            String subid=assetAction.getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }
/**
 * 8	已转出
 * 0	在库
 * 1	已领用
 * 2	报废确认中
 * 3	已借用
 * 4	转出确认中
 * 5	调拨确认中
 * 6	借用确认中
 * 7	已减账
 */
            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" dybmdesc,sykedesc,zrrdesc,id,ggxh,pp,zczt,swzcspan,swzc,zclx,zclxmc,swpp,swggxh,rkrq";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select    e.subcompanyname dybmdesc,f.departmentname sykedesc,g.lastname zrrdesc,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id  left join uf_swzcpp d on a.pp=d.id  left join HrmSubCompany e on a.dybm=e.id left join HrmDepartment f on a.syks=f.id left join hrmresource g on a.zrr=g.id  where len(isnull(a.xzgbxtzc,''))<=0  and  "+sqlwhere+" ) a1 "	;

            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            //table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");//swzc
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "规格型号", "swggxh","swggxh"));
            table.getColumns().add(new WeaTableColumn("10%", "入库日期", "rkrq","rkrq"));
            table.getColumns().add(new WeaTableColumn("10%", "使用部门", "dybmdesc","dybmdesc"));
            table.getColumns().add(new WeaTableColumn("10%", "使用科室", "sykedesc","sykedesc"));
            table.getColumns().add(new WeaTableColumn("10%", "责任人", "zrrdesc","zrrdesc"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    public  Map<String, Object> SysDiscovery(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag=true;
        String mess="";
        String uuid= UUID.randomUUID().toString();//本次任务的 一个标识
        try{
            List<Object> uf_zcpdrwxfs=new ArrayList<>();
            Uf_zcpdrwxfBaseService Uf_zcpdrwxfBaseService=new Uf_zcpdrwxfBaseService();
            SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String currentdate=sim.format(new Date()).split(" ")[0];
            String currenttime=sim.format(new Date()).split(" ")[1];
            uf_zcpdrwxf uf_zcpdrwxf=new uf_zcpdrwxf();

            String bm= Util.null2String((String)params.get("bm"));//部门
            String sblx= Util.null2String((String)params.get("sblx"));//设备类型
            String requestname=Util.null2String((String)params.get("requestname"));//任务标题
            String year=Util.null2String((String)params.get("year"));//年份
            String qx=Util.null2String((String)params.get("qx"));//期限
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产
            log.writeLog("begin---bm>"+bm);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---requestname>"+requestname);
            log.writeLog("begin---year>"+year);
            log.writeLog("begin---qx>"+qx);
            log.writeLog("begin---notpd>"+notpd);
            uf_zcpdrwxf.setBxpdsb(notpd);
            uf_zcpdrwxf.setDatauuid(uuid);
            uf_zcpdrwxf.setPdbm(bm);
            uf_zcpdrwxf.setPdnf(year);
            uf_zcpdrwxf.setPdqx(qx);
            uf_zcpdrwxf.setRwbt(requestname);
            uf_zcpdrwxf.setSblx(sblx);
            uf_zcpdrwxf.setXfrq(currentdate);
            uf_zcpdrwxf.setXfry(user.getUID());
            uf_zcpdrwxf.setModedatacreater(user.getUID()+"");
            uf_zcpdrwxfs.add(uf_zcpdrwxf);
            //拼接  实物资产的数据 sql

            //1=1 and a.zczt in (0,1,3,4,5,6) and isnull(a.dybm,-1)>0 and isnull(a.syks,-1)>0 and isnull(a.zrr,-1)>0
            String wheresql=" 1=1 and isnull(a.dybm,-1) >0 and isnull(a.zczt,-1) in (0,1,3,4,5,6) and isnull(a.syks,-1)>0 and isnull(a.zrr,-1)>0  ";
            if(!"".equals(bm)){
                if(bm.endsWith(",")){
                    bm=bm.substring(0,bm.length()-1);
                }
                wheresql=wheresql+" and a.dybm in ("+bm+")";
            }
            if(!"".equals(sblx)){
                if(sblx.endsWith(",")) {
                    sblx = sblx.substring(0, sblx.length() - 1);
                }
                wheresql=wheresql+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                wheresql=wheresql+" and a.id not in ("+notpd+")";
            }
            //不可以重复盘点
            wheresql =wheresql+" and not exists (select 1 from uf_grzcpdjl b where b.pdnf='"+year+"' and b.swzcid=a.id and isnull(b.sfyx,-1) in (-1,0) ) ";
            String sql="select * from uf_swzczmxx a where "+wheresql;
            String countsql="select count(1) counts from uf_swzczmxx a where "+wheresql;
            String groupbysql="select a.dybm,count(1) counts from uf_swzczmxx a where "+wheresql+"  group by a.dybm";
            log.writeLog("begin---sql>"+sql);
            log.writeLog("begin---countsql>"+countsql);
            log.writeLog("begin---groupbysql>"+groupbysql);
            RecordSet re=new RecordSet();
            RecordSet re1=new RecordSet();
            RecordSet re2=new RecordSet();
            re1.execute(countsql);
            if(re1.next()){
                int count=Util.getIntValue(re1.getString("counts"),0);
                if(count>0){
                    uf_zcpdrwxf.setPdsbzs(count);
                }else{
                    throw  new Exception("没有盘点清单");
                }
            }else{
                throw  new Exception("没有盘点清单");
            }
            String errormess="";
            errormess=Uf_zcpdrwxfBaseService.getObjMapList(uf_zcpdrwxfs,null);
            if(!"".equals(errormess)){
                throw  new Exception(errormess);
            }
            String mainid=getMainid(uuid);
            if("".equals(mainid)){
                throw  new Exception("未生成主数据!");
            }
            //先插入 资产系统管理员任务表 在插入个人盘点中
            //开始盘点 部门
            Uf_bmzcpdrwBaseService Uf_bmzcpdrwBaseService=new Uf_bmzcpdrwBaseService();
            List<Object> uf_bmzcpdrws=new ArrayList<>();
            uf_bmzcpdrw uf_bmzcpdrw=null;
            re2.execute(groupbysql);
            while(re2.next()){
                uf_bmzcpdrw=new uf_bmzcpdrw();
                int dybm=Util.getIntValue(re2.getString("dybm"),0) ;
                int counts=Util.getIntValue(re2.getString("counts"),0) ;
                uf_bmzcpdrw.setDatauuid(uuid);
                uf_bmzcpdrw.setPdbm(dybm);
                uf_bmzcpdrw.setBxpdsb(notpd);
                uf_bmzcpdrw.setPdnf(year);
                uf_bmzcpdrw.setPdqx(qx);
                //uf_bmzcpdrw.setPdrwbt(requestname);
                uf_bmzcpdrw.setPdrwbt(mainid);
                uf_bmzcpdrw.setPdsbzs(counts);
                uf_bmzcpdrw.setXfrq(currentdate);
                uf_bmzcpdrw.setPdxfr(user.getUID());
                uf_bmzcpdrw.setSzsjrw(mainid);
                uf_bmzcpdrw.setZrr(getSwSysadmin(dybm+""));
                uf_bmzcpdrw.setModedatacreater(user.getUID()+"");
                uf_bmzcpdrws.add(uf_bmzcpdrw);
            }
            if(uf_bmzcpdrws.size()>0){
                errormess=Uf_bmzcpdrwBaseService.getObjMapList(uf_bmzcpdrws,null);
                if(!"".equals(errormess)){
                    throw  new Exception(errormess);
                }
            }
            JSONObject Subreid=getSubRwidByuuid(uuid);//部门对应任务ID
            //开始盘点 资产 盘点池  需要设置对应的 部门任务ID 用于盘点的 时候显示  盘点的任务情况

            uf_grzcpdjlBaseService uf_grzcpdjlBaseService=new uf_grzcpdjlBaseService();
            List<Object> uf_grzcpdjls=new ArrayList<>();
            re.execute(sql);
            uf_grzcpdjl uf_grzcpdjl=null;
            while(re.next()){
                uf_grzcpdjl=new uf_grzcpdjl();
                String id=Util.null2String(re.getString("id")) ;
                String kpwybh=Util.null2String(re.getString("kpwybh")) ;
                String zclx=Util.null2String(re.getString("zclx")) ;
                String swzcbh=Util.null2String(re.getString("swzcbh")) ;
                String zcmc=Util.null2String(re.getString("zcmc")) ;
                String ggxh=Util.null2String(re.getString("ggxh")) ;
                String macdz=Util.null2String(re.getString("macdz")) ;
                String jqm=Util.null2String(re.getString("jqm")) ;
                int dybm=Util.getIntValue(re.getString("dybm"),0);
                int zrr=Util.getIntValue(re.getString("zrr"), 0);
                int pp= Util.getIntValue(re.getString("pp"),0);
                int rwid=Util.getIntValue(Subreid.getString(dybm+""),0);
                int syks=Util.getIntValue(re.getString("syks"),0);
                if(dybm==0||rwid<=0){
                    throw  new Exception(zcmc+"没有找到盘点部门任务清单!"+dybm+"--uuid"+uuid);
                }
                uf_grzcpdjl.setDatauuid(uuid);
                uf_grzcpdjl.setGgxh(Util.getIntValue(ggxh,0));
                uf_grzcpdjl.setLypdfs(0);
                uf_grzcpdjl.setMacdz(macdz);
                uf_grzcpdjl.setPdnf(year);
                uf_grzcpdjl.setPdqx(qx);
                //uf_grzcpdjl.setPdrwbt(requestname);
                uf_grzcpdjl.setPdrwbt(mainid);
                uf_grzcpdjl.setPdsb(zclx);
                uf_grzcpdjl.setPdxfr(user.getUID());
                uf_grzcpdjl.setPdzrr(0+"");
                uf_grzcpdjl.setPp(pp);
                uf_grzcpdjl.setSblx(Util.getIntValue(zclx,0 ) );
                uf_grzcpdjl.setSjly(mainid);
                uf_grzcpdjl.setSzglypdrw(Util.getIntValue(mainid,0));
                uf_grzcpdjl.setSwzcbh(swzcbh);
                uf_grzcpdjl.setXfrq(currentdate);
                uf_grzcpdjl.setZrbm(dybm);
                uf_grzcpdjl.setSjzrr(zrr);
                uf_grzcpdjl.setPdzrr(zrr+"");
                uf_grzcpdjl.setSwzcid(id);
                uf_grzcpdjl.setSzbmpdrw(rwid);
                uf_grzcpdjl.setZrks(syks);
                uf_grzcpdjl.setModedatacreater(user.getUID()+"");
                uf_grzcpdjls.add(uf_grzcpdjl);
            }
            if(uf_grzcpdjls!=null&&uf_grzcpdjls.size()>0){
                errormess=uf_grzcpdjlBaseService.getObjMapList(uf_grzcpdjls,null);
                if(!"".equals(errormess)){
                    throw  new Exception(errormess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }
        if(!flag){
            RecordSet re=new RecordSet();
            re.execute("delete from Uf_zcpdrwxf where datauuid='"+uuid+"' ");
            re.execute("delete from uf_bmzcpdrw where datauuid='"+uuid+"' ");
            re.execute("delete from uf_grzcpdjl where datauuid='"+uuid+"' ");
        }
        apidatas.put("flag", flag);
        apidatas.put("mess", mess);
        return apidatas;
    }

    /**
     * 获取主数据ID
     * @param uuid
     * @return
     */
    public String getMainid(String uuid){
        RecordSet re=new RecordSet();
        String sql="select * from Uf_zcpdrwxf where datauuid='"+uuid+"'";
        re.execute(sql);
        String mainid="";
        while(re.next()){
            mainid=Util.null2String(re.getString("id")).trim();
        }
        return mainid;
    }

    /**
     * 获取 部门的 实物资产管理员
     * @param bm
     * @return
     */
    public String getSwSysadmin(String bm){
        String swzcgly="0";
        bm=Util.null2String(bm);
        if("".equals(bm)){
            return swzcgly;
        }

        String sql="select swzcgly from HrmSubcompanyDefined where subcomid="+bm;
        RecordSet re=new RecordSet();
        re.execute(sql);
        if(re.next()){
            swzcgly=Util.getIntValue(re.getString("swzcgly"),0)+"";
        }
        return swzcgly;
    }
    /**
     * 获取 科室的 实物资产管理员
     * @param bm
     * @return
     */
    public String getSwKsSysadmin(String bm){
        String swzcgly="0";
        bm=Util.null2String(bm);
        if("".equals(bm)){
            return swzcgly;
        }

        String sql=" select swzcgly from HrmDepartmentDefined where deptid="+bm;
        RecordSet re=new RecordSet();
        re.execute(sql);
        if(re.next()){
            swzcgly=Util.getIntValue(re.getString("swzcgly"), 0) +"";
        }
        return swzcgly;
    }
    //个人 盘点统计
    public  Map<String, Object> SysSingleDiscovery(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag=true;
        String mess="";
        String uuid= UUID.randomUUID().toString();//本次任务的 一个标识
        try{
            List<Object> uf_zcpdrwxfs=new ArrayList<>();
            Uf_zcpdrwxfBaseService Uf_zcpdrwxfBaseService=new Uf_zcpdrwxfBaseService();
            SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String currentdate=sim.format(new Date()).split(" ")[0];
            String currenttime=sim.format(new Date()).split(" ")[1];
            uf_zcpdrwxf uf_zcpdrwxf=new uf_zcpdrwxf();

            String bm= Util.null2String((String)params.get("bm"));//部门
            String sblx= Util.null2String((String)params.get("sblx"));//设备类型
            String requestname=Util.null2String((String)params.get("requestname"));//任务标题
            String year=Util.null2String((String)params.get("year"));//年份
            String qx=Util.null2String((String)params.get("qx"));//期限
            String notpd=Util.null2String((String)params.get("notpd"));//需要盘点资产
            log.writeLog("begin---bm>"+bm);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---requestname>"+requestname);
            log.writeLog("begin---year>"+year);
            log.writeLog("begin---qx>"+qx);
            log.writeLog("begin---notpd>"+notpd);
            uf_zcpdrwxf.setBxpdsb(notpd);
            uf_zcpdrwxf.setDatauuid(uuid);
            uf_zcpdrwxf.setPdbm(bm);
            uf_zcpdrwxf.setPdnf(year);
            uf_zcpdrwxf.setPdqx(qx);
            uf_zcpdrwxf.setRwbt(requestname);
            uf_zcpdrwxf.setSblx(sblx);
            uf_zcpdrwxf.setXfrq(currentdate);
            uf_zcpdrwxf.setXfry(user.getUID());
            uf_zcpdrwxfs.add(uf_zcpdrwxf);
            //拼接  实物资产的数据 sql
            String wheresql=" 1=1 and isnull(a.dybm,-1) >0  and isnull(a.zczt,-1) in (0,1) ";
            if(!"".equals(bm)){
                if(bm.endsWith(",")){
                    bm=bm.substring(0,bm.length()-1);
                }
                wheresql=wheresql+" and a.dybm in ("+bm+")";
            }
            if(!"".equals(sblx)){
                if(sblx.endsWith(",")) {
                    sblx = sblx.substring(0, sblx.length() - 1);
                }
                wheresql=wheresql+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                wheresql=wheresql+" and a.id  in ("+notpd+")";
            }else{
                throw  new Exception("未选中盘点资产!");
            }
            //不可以重复盘点
            wheresql =wheresql+" and not exists (select 1 from uf_grzcpdjl b where b.pdnf='"+year+"' and b.swzcid=a.id and isnull(b.sfyx,-1) in (-1,0) ) ";
            String sql="select * from uf_swzczmxx a where "+wheresql;
            String countsql="select count(1) counts from uf_swzczmxx a where "+wheresql;
            String groupbysql="select a.dybm,count(1) counts from uf_swzczmxx a where "+wheresql+"  group by a.dybm";
            log.writeLog("begin---sql>"+sql);
            log.writeLog("begin---countsql>"+countsql);
            log.writeLog("begin---groupbysql>"+groupbysql);
            RecordSet re=new RecordSet();
            RecordSet re1=new RecordSet();
            RecordSet re2=new RecordSet();
            re1.execute(countsql);
            if(re1.next()){
                int count=Util.getIntValue(re1.getString("counts"),0);
                if(count>0){
                    uf_zcpdrwxf.setPdsbzs(count);
                }else{
                    throw  new Exception("没有盘点清单");
                }
            }else{
                throw  new Exception("没有盘点清单");
            }
            String errormess="";
            errormess=Uf_zcpdrwxfBaseService.getObjMapList(uf_zcpdrwxfs,null);
            if(!"".equals(errormess)){
                throw  new Exception(errormess);
            }
            String mainid=getMainid(uuid);
            if("".equals(mainid)){
                throw  new Exception("未生成主数据!");
            }
            //先插入 资产系统管理员任务表 在插入个人盘点中
            //开始盘点 部门
            Uf_bmzcpdrwBaseService Uf_bmzcpdrwBaseService=new Uf_bmzcpdrwBaseService();
            List<Object> uf_bmzcpdrws=new ArrayList<>();
            uf_bmzcpdrw uf_bmzcpdrw=null;
            re2.execute(groupbysql);
            while(re2.next()){

                uf_bmzcpdrw=new uf_bmzcpdrw();
                int dybm=Util.getIntValue(re2.getString("dybm"),0) ;
                int counts=Util.getIntValue(re2.getString("counts"),0) ;
                String Zrr=getSwSysadmin(dybm+"");
                if("0".equals(Zrr)){
                    throw  new Exception(dybm+"没有维护资产管理员不能盘点!");
                }
                uf_bmzcpdrw.setDatauuid(uuid);
                uf_bmzcpdrw.setPdbm(dybm);
                uf_bmzcpdrw.setBxpdsb(notpd);
                uf_bmzcpdrw.setPdnf(year);
                uf_bmzcpdrw.setPdqx(qx);
                //uf_bmzcpdrw.setPdrwbt(requestname);
                uf_bmzcpdrw.setPdrwbt(mainid);
                uf_bmzcpdrw.setPdsbzs(counts);
                uf_bmzcpdrw.setXfrq(currentdate);
                uf_bmzcpdrw.setPdxfr(user.getUID());
                uf_bmzcpdrw.setSzsjrw(mainid);
                uf_bmzcpdrw.setZrr(Zrr);
                uf_bmzcpdrws.add(uf_bmzcpdrw);
            }
//            if(uf_bmzcpdrws.size()>0){
//                errormess=Uf_bmzcpdrwBaseService.getObjMapList(uf_bmzcpdrws,null);
//                if(!"".equals(errormess)){
//                    throw  new Exception(errormess);
//                }
//            }


            //开始盘点 资产 盘点池
            uf_grzcpdjlBaseService uf_grzcpdjlBaseService=new uf_grzcpdjlBaseService();
            List<Object> uf_grzcpdjls=new ArrayList<>();
            re.execute(sql);
            uf_grzcpdjl uf_grzcpdjl=null;
            //直接 盘点无需  再次分发
            while(re.next()){
                uf_grzcpdjl=new uf_grzcpdjl();
                String id=Util.null2String(re.getString("id")) ;
                String kpwybh=Util.null2String(re.getString("kpwybh")) ;
                String zclx=Util.null2String(re.getString("zclx")) ;
                String swzcbh=Util.null2String(re.getString("swzcbh")) ;
                String zcmc=Util.null2String(re.getString("zcmc")) ;
                String ggxh=Util.null2String(re.getString("ggxh")) ;
                String macdz=Util.null2String(re.getString("macdz")) ;
                String jqm=Util.null2String(re.getString("jqm")) ;
                int dybm=Util.getIntValue(re.getString("dybm"),0);
                int zrr=Util.getIntValue(re.getString("zrr"), 0);
                int pp= Util.getIntValue(re.getString("pp"),0);

                uf_grzcpdjl.setDatauuid(uuid);
                uf_grzcpdjl.setGgxh(Util.getIntValue(ggxh,0));
                uf_grzcpdjl.setLypdfs(0);
                uf_grzcpdjl.setMacdz(macdz);
                uf_grzcpdjl.setPdnf(year);
                uf_grzcpdjl.setPdqx(qx);
                //uf_grzcpdjl.setPdrwbt(requestname);
                uf_grzcpdjl.setPdrwbt(mainid);
                uf_grzcpdjl.setPdsb(zclx);
                uf_grzcpdjl.setPdxfr(user.getUID());
                uf_grzcpdjl.setPdzrr(0+"");
                uf_grzcpdjl.setPp(pp);
                uf_grzcpdjl.setSblx(Util.getIntValue(zclx,0 ) );
                uf_grzcpdjl.setSjly(mainid);
                uf_grzcpdjl.setSzglypdrw(Util.getIntValue(mainid,0));
                uf_grzcpdjl.setSwzcbh(swzcbh);
                uf_grzcpdjl.setXfrq(currentdate);
                uf_grzcpdjl.setZrbm(dybm);
                uf_grzcpdjl.setSjzrr(zrr);
                uf_grzcpdjl.setPdzrr(zrr+"");
                uf_grzcpdjl.setSwzcid(id);
                uf_grzcpdjl.setSfkspd(0);//直接开始盘点

                uf_grzcpdjls.add(uf_grzcpdjl);
            }
            if(uf_grzcpdjls!=null&&uf_grzcpdjls.size()>0){
                errormess=uf_grzcpdjlBaseService.getObjMapList(uf_grzcpdjls,null);
                if(!"".equals(errormess)){
                    throw  new Exception(errormess);
                }
            }
            iniPermissionByuuid(uuid);//设置权限
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }
        if(!flag){
            RecordSet re=new RecordSet();
            re.execute("delete from Uf_zcpdrwxf where datauuid='"+uuid+"' ");
            re.execute("delete from uf_bmzcpdrw where datauuid='"+uuid+"' ");
            re.execute("delete from uf_grzcpdjl where datauuid='"+uuid+"' ");
        }
        apidatas.put("flag", flag);
        apidatas.put("mess", mess);
        return apidatas;
    }

    /**
     * 根据UUID 获取部门对对应的任务ID
     * @param uuid
     * @return
     */
    public JSONObject getSubRwidByuuid(String uuid){
        JSONObject json=new JSONObject();
        int subrwid=0;
        RecordSet re=new RecordSet();
        String sql="select id,pdbm from uf_bmzcpdrw where datauuid='"+uuid+"'   and isnull(pdbm,-1)>0";
        log.writeLog("getSubRwidByuuid--->"+sql);
        re.execute(sql);
        while(re.next()){
            subrwid=Util.getIntValue(re.getString("id"), 0);
            int pdbm=Util.getIntValue(re.getString("pdbm"), 0);
            if(pdbm<=0){
                continue;
            }
            json.put(pdbm+"", subrwid+"");
        }
        return json;
    }

    /**
     * 初始化 权限 uuid
     * @param uuid
     */
    public  void iniPermissionByuuid(final String uuid){
        new Thread(new Runnable() {
            @Override
            public void run() {
                ModeRightInfo mri=new ModeRightInfo();
                //盘点任务清单
                RecordSet re=new RecordSet();
                String sql="select * from Uf_zcpdrwxf where datauuid='"+uuid+"'";
                re.execute(sql);
                while(re.next()){
                    int id=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(weaver.general.Util.getIntValue(1+"",0), weaver.general.Util.getIntValue(new uf_zcpdrwxf().getFormmodeid(),0), weaver.general.Util.getIntValue(id+"",0));
                }
                //部门
                sql="select * from uf_bmzcpdrw where datauuid='"+uuid+"'";
                re.execute(sql);
                while(re.next()){
                    int id=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(weaver.general.Util.getIntValue(1+"",0), weaver.general.Util.getIntValue(new uf_bmzcpdrw().getFormmodeid(),0), weaver.general.Util.getIntValue(id+"",0));
                }

                //科室
                sql="select * from uf_kszcpdrw where datauuid='"+uuid+"'";
                re.execute(sql);
                while(re.next()){
                    int id=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(weaver.general.Util.getIntValue(1+"",0), weaver.general.Util.getIntValue(new uf_kszcpdrw().getFormmodeid(),0), weaver.general.Util.getIntValue(id+"",0));
                }
                //个人
                sql="select * from uf_grzcpdjl where datauuid='"+uuid+"'";
                re.execute(sql);
                while(re.next()){
                    int id=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(weaver.general.Util.getIntValue(1+"",0), weaver.general.Util.getIntValue(new uf_grzcpdjl().getFormmodeid(),0), weaver.general.Util.getIntValue(id+"",0));
                }
            }
        }).start();
    }
    //部门盘点清单列表

    /**
     * 根据 任务的ID来获取 需要 下发的  资产列表
     * 1：状态为 不能盘点的 资产
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> getSubTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String) weaver.general.Util.null2String(params.get("sbzt")) ;//设备状态
            String rq=(String) weaver.general.Util.null2String(params.get("rq")) ;//入库日期
            String dybm=(String) weaver.general.Util.null2String(params.get("bm")) ;//所在单位
            String year=(String) weaver.general.Util.null2String(params.get("year")) ;//盘点年度
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//任务ID
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f79285711111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";

            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }


            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            assetAction assetAction=new assetAction();
            String subid=assetAction.getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }

            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	"  dybmdesc,sykedesc,zrrdesc,id,ggxh,pp,zczt,swzcspan,swzc,zclx,zclxmc,swpp,swggxh,rkrq";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;

            String fromSql=" from (select  e.subcompanyname dybmdesc,f.departmentname sykedesc,g.lastname zrrdesc,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id left join HrmSubCompany e on a.dybm=e.id left join HrmDepartment f on a.syks=f.id left join hrmresource g on a.zrr=g.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                           " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" ) a1 "	;

            log.writeLog("getSubTableDataSW-->"+fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            //table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");//swzc
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");

            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "规格型号", "swggxh","swggxh"));
            table.getColumns().add(new WeaTableColumn("10%", "入库日期", "rkrq","rkrq"));
            table.getColumns().add(new WeaTableColumn("10%", "使用部门", "dybmdesc","dybmdesc"));
            table.getColumns().add(new WeaTableColumn("10%", "使用科室", "sykedesc","sykedesc"));
            table.getColumns().add(new WeaTableColumn("10%", "责任人", "zrrdesc","zrrdesc"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }

    /**
     * 部门下发科室  盘点
     * @param params
     * @param user
     * @return
     */
    public  Map<String, Object> IssueDepDiscovery(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag = true;
        String mess = "";
        String uuid = UUID.randomUUID().toString();//本次任务的 一个标识
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        try{
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String((String)params.get("sblx")) ;//设备类型
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//部门盘点任务ID
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产
            String syks1=Util.null2String((String)params.get("syks"));//使用科室
            log.writeLog("begin---pp>"+pp);
            log.writeLog("begin---ggxh>"+ggxh);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---rwid>"+rwid);
            log.writeLog("begin---notpd>"+notpd);

            String sqlwhere =" 1=1 ";
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                sqlwhere=sqlwhere+" and a.id not in ("+notpd+")";
            }
            if(!"".equals(syks1)){
                if(syks1.endsWith(",")){
                    syks1=syks1.substring(0,syks1.length()-1);
                }
                sqlwhere=sqlwhere+" and a.syks not in ("+syks1+")";
            }
            //数量
            String countSql=" select   syks,count(1) counts from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                    " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+"  group by  syks"	;

            //资产明细
            log.writeLog("IssueDepDiscovery-->"+countSql);
            //查询任务的实体类
            RecordSet re=new RecordSet();
            RecordSet re1=new RecordSet();
            RecordSet re2=new RecordSet();
            String sql="select * from uf_bmzcpdrw where id="+rwid;
            re.execute(sql);
            String sblxmodel="";
            String pdrwbt="";
            String pdnf="";
            String pdqx="";
            String pdbm="";
            if(re.next()){
                sblxmodel=Util.null2String(re.getString("sblx"));
                pdrwbt=Util.null2String(re.getString("pdrwbt"));
                pdnf=Util.null2String(re.getString("pdnf"));
                pdqx=Util.null2String(re.getString("pdqx"));
                pdbm=Util.null2String(re.getString("pdbm"));
            }else{
                throw new Exception("无法获取部门盘点任务信息");
            }
            //插入 科室盘点表
            JSONObject ksjson= new JSONObject();
            List<Object> listuf_kszcpdrw=new ArrayList<>();
            uf_kszcpdrwBaseService uf_kszcpdrwBaseService=new uf_kszcpdrwBaseService();
            re1.execute(countSql);
            while(re1.next()){
                int syks=Util.getIntValue(re1.getString("syks"),0);
                int counts=Util.getIntValue(re1.getString("counts"),0);
                //判断是否已经存在
                String pdksid=getksRwByDepRwid(syks+"",rwid+"");
                if(!"".equals(Util.null2String(pdksid).trim())){
                    ksjson.put(syks+"",pdksid);
                    continue;
                }
                uf_kszcpdrw=new uf_kszcpdrw();
                uf_kszcpdrw.setBxpdsb(notpd);
                uf_kszcpdrw.setDatauuid(uuid);
                uf_kszcpdrw.setPdbm(Util.getIntValue(pdbm, 0));
                uf_kszcpdrw.setPdks(syks);
                uf_kszcpdrw.setPdnf(pdnf);
                uf_kszcpdrw.setPdqx(pdqx);
                uf_kszcpdrw.setPdrwbt(Util.getIntValue(pdrwbt, 0));
                uf_kszcpdrw.setPdsbzs(counts);
                uf_kszcpdrw.setPdxfr(user.getUID());
                uf_kszcpdrw.setSblx(sblxmodel);
                uf_kszcpdrw.setXfrq(currentdate);
                uf_kszcpdrw.setSzbmpdrw(rwid);
                uf_kszcpdrw.setPdzt(0);

                listuf_kszcpdrw.add(uf_kszcpdrw);
            }
            if(listuf_kszcpdrw.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(listuf_kszcpdrw,null);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }else{
                throw new Exception("无法获取可盘点科室资产信息!");
            }
            //开始更新  个人资产池里面的数据
            List<Map<String,Object>> sqlmap=new ArrayList<>();
            Map<String,Object> map=null;
            if(listuf_kszcpdrw.size()>0){
                getDepPdByuuid(uuid, ksjson);
            }

            if(ksjson!=null&&ksjson.size()>0){
                Set<String> key=ksjson.keySet();
                for(String str:key){
                    Object[] param2=new Object[3];
                    String fromSql="select id from (select  b1.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                            " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" and a.syks='"+str+"') a1 "	;
                    //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                    log.writeLog(fromSql);
                    log.writeLog("rwid"+ksjson.getString(str));


                    String sql12="update uf_grzcpdjl  set lypdfs=?,szkspdrw=?,sjly=? where id in ("+fromSql+")";
                    param2[0]=1;
                    param2[1]=ksjson.getString(str);
                    param2[2]=rwid;
                    map=new HashMap<>();
                    map.put("sql",sql12);
                    map.put("params",param2);
                    sqlmap.add(map);
                }
            }else{
                throw new Exception("科室盘点未写入!");
            }
            if(sqlmap!=null&&sqlmap.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(null,sqlmap);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }
        if(!"".equals(mess)){
            RecordSet re=new RecordSet();
            re.execute("delete from uf_kszcpdrw where datauuid='"+uuid+"'");
        }
        apidatas.put("flag", flag);
        apidatas.put("mess", mess);

        return apidatas;
    }
    public String getksRwByDepRwid(String ksid,String rwid){
        RecordSet re=new RecordSet();
        String ksrwid="";
        String sql="select * from uf_kszcpdrw where Szbmpdrw="+rwid+" and Pdks="+ksid;
        re.execute(sql);
        while(re.next()){
            ksrwid=Util.null2String(re.getString("id")).trim();
        }
        return ksrwid;
    }
    /**
     * 部门个人  盘点
     * @param params
     * @param user
     * @return
     */
    public  Map<String, Object> IssueDepSingleDiscovery(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag = true;
        String mess = "";
        String uuid = UUID.randomUUID().toString();//本次任务的 一个标识
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        try{
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String((String)params.get("sblx")) ;//设备类型
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//部门盘点任务ID
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产
            String syks=Util.null2String((String)params.get("syks"));//使用科室
            log.writeLog("begin---pp>"+pp);
            log.writeLog("begin---ggxh>"+ggxh);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---rwid>"+rwid);
            log.writeLog("begin---notpd>"+notpd);

            String sqlwhere =" 1=1 ";
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                sqlwhere=sqlwhere+" and a.id not in ("+notpd+")";
            }
            if(!"".equals(syks)){
                if(syks.endsWith(",")){
                    syks=syks.substring(0,syks.length()-1);
                }
                sqlwhere=sqlwhere+" and a.syks not in ("+syks+")";
            }

            uf_kszcpdrwBaseService uf_kszcpdrwBaseService=new uf_kszcpdrwBaseService();

            //开始更新  个人资产池里面的数据
            List<Map<String,Object>> sqlmap=new ArrayList<>();
            Map<String,Object> map=null;

                    Object[] param2=new Object[3];
                    String fromSql="select id from (select  b1.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                            " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" ) a1 "	;
                    //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                    log.writeLog("IssueDepSingleDiscovery-->"+fromSql);
                    String sql12="update uf_grzcpdjl  set sfkspd=? where id in ("+fromSql+")";
                    param2[0]=0;
                    map=new HashMap<>();
                    map.put("sql",sql12);
                    map.put("params",param2);
                    sqlmap.add(map);
            if(sqlmap!=null&&sqlmap.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(null,sqlmap);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }

        apidatas.put("flag", flag);
        apidatas.put("mess", mess);

        return apidatas;
    }
    /**
     * 部门资产管理员个人  盘点
     * @param params
     * @param user
     * @return
     */
    public  Map<String, Object> IssueDepSysadminDiscovery(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag = true;
        String mess = "";
        String uuid = UUID.randomUUID().toString();//本次任务的 一个标识
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        try{
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String((String)params.get("sblx")) ;//设备类型
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//部门盘点任务ID
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产
            String syks=Util.null2String((String)params.get("syks"));//使用科室
            log.writeLog("begin---pp>"+pp);
            log.writeLog("begin---ggxh>"+ggxh);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---rwid>"+rwid);
            log.writeLog("begin---notpd>"+notpd);

            String sqlwhere =" 1=1 ";
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                sqlwhere=sqlwhere+" and a.id not in ("+notpd+")";
            }
            if(!"".equals(syks)){
                if(syks.endsWith(",")){
                    syks=syks.substring(0,syks.length()-1);
                }
                sqlwhere=sqlwhere+" and a.syks not in ("+syks+")";
            }
            uf_kszcpdrwBaseService uf_kszcpdrwBaseService=new uf_kszcpdrwBaseService();
            RecordSet re=new RecordSet();
            String countSql=" select   dybm,count(1) counts from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                            " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+"  group by  dybm"	;
            //开始更新  个人资产池里面的数据
            List<Map<String,Object>> sqlmap=new ArrayList<>();
            Map<String,Object> map=null;
            re.execute(countSql);
            while(re.next()){
                String dybmmodel=Util.null2String(re.getString("dybm")).trim() ;
                Object[] param2=new Object[2];
                String fromSql="select id from (select  b1.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_bmzcpdrw a1,uf_grzcpdjl b1 " +
                        " where a1.id="+rwid+" and a1.id=b1.szbmpdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=0 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" and b1.zrbm='"+dybmmodel+"' and isnull(b1.zrbm,0)>0 ) a1 "	;
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                log.writeLog("IssueDepSysadminDiscovery-->"+fromSql);
                String sql12="update uf_grzcpdjl  set sfkspd=?,sjzrr=? where id in ("+fromSql+")";
                param2[0]=0;
                param2[1]=getSwSysadmin(dybmmodel);
                //getSwSysadmin
                map=new HashMap<>();
                map.put("sql",sql12);
                map.put("params",param2);
                sqlmap.add(map);
            }

            if(sqlmap!=null&&sqlmap.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(null,sqlmap);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }

        apidatas.put("flag", flag);
        apidatas.put("mess", mess);

        return apidatas;
    }

    public JSONObject getDepPdByuuid(String uuid,JSONObject json){
        if(json==null){
            json=new JSONObject();
        }
        //JSONObject json=new JSONObject();
        int subrwid=0;
        RecordSet re=new RecordSet();
        String sql="select id,pdks from uf_kszcpdrw where datauuid='"+uuid+"'   and isnull(pdks,-1)>0";
        log.writeLog("getDepPdByuuid--->"+sql);
        re.execute(sql);
        while(re.next()){
            subrwid=Util.getIntValue(re.getString("id"), 0);
            int pdbm=Util.getIntValue(re.getString("pdks"), 0);
            if(pdbm<=0){
                continue;
            }
            json.put(pdbm+"", subrwid+"");
        }
        return json;
    }


    /**
     * 根据 任务的ID来获取 需要 下发的  资产列表
     * 1：状态为 不能盘点的 资产
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> getDepTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String) weaver.general.Util.null2String(params.get("sbzt")) ;//设备状态
            String rq=(String) weaver.general.Util.null2String(params.get("rq")) ;//入库日期
            String dybm=(String) weaver.general.Util.null2String(params.get("bm")) ;//所在单位
            String year=(String) weaver.general.Util.null2String(params.get("year")) ;//盘点年度
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//任务ID
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f79285711111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";

            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }


            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            assetAction assetAction=new assetAction();
            String subid=assetAction.getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }

            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" id,ggxh,pp,zczt,swzcspan,swzc,zclx,zclxmc,swpp,swggxh,rkrq";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select  a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_kszcpdrw a1,uf_grzcpdjl b1 " +
                    " where a1.id="+rwid+" and a1.id=b1.szkspdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=1 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" ) a1 "	;

            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            //table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");//swzc
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "规格型号", "swggxh","swggxh"));
            table.getColumns().add(new WeaTableColumn("10%", "入库日期", "rkrq","rkrq"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    /**
     * 科室 资产管理员个人以及责任人  盘点
     * @param params
     * @param user
     * @return
     */
    public  Map<String, Object> IssueKsSysadminDiscovery(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag = true;
        String mess = "";
        String uuid = UUID.randomUUID().toString();//本次任务的 一个标识
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        try{
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String((String)params.get("sblx")) ;//设备类型
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//部门盘点任务ID
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产

            log.writeLog("begin---pp>"+pp);
            log.writeLog("begin---ggxh>"+ggxh);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---rwid>"+rwid);
            log.writeLog("begin---notpd>"+notpd);

            String sqlwhere =" 1=1 ";
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                sqlwhere=sqlwhere+" and a.id not in ("+notpd+")";
            }

            uf_kszcpdrwBaseService uf_kszcpdrwBaseService=new uf_kszcpdrwBaseService();
            RecordSet re=new RecordSet();
            String countSql=" select   a.syks,count(1) counts from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_kszcpdrw a1,uf_grzcpdjl b1 " +
                    " where a1.id="+rwid+" and a1.id=b1.szkspdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=1 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+"  group by a.syks "	;

            //开始更新  个人资产池里面的数据
            List<Map<String,Object>> sqlmap=new ArrayList<>();
            Map<String,Object> map=null;
            re.execute(countSql);
            while(re.next()){
                String dybmmodel=Util.null2String(re.getString("syks")).trim() ;
                String sjzrr=getSwKsSysadmin(dybmmodel);
                if("0".equals(sjzrr)){
                    continue;
                }
                Object[] param2=new Object[2];
                String fromSql="select id from (select  b1.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_kszcpdrw a1,uf_grzcpdjl b1 " +
                        " where a1.id="+rwid+" and a1.id=b1.szkspdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=1 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" and b1.zrks='"+dybmmodel+"' and isnull(b1.zrks,0)>0 ) a1 "	;
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                log.writeLog("IssueDepSysadminDiscovery-->"+fromSql);
                String sql12="update uf_grzcpdjl  set sfkspd=?,sjzrr=? where id in ("+fromSql+")";
                param2[0]=0;
                param2[1]=getSwKsSysadmin(dybmmodel);
                //getSwSysadmin
                map=new HashMap<>();
                map.put("sql",sql12);
                map.put("params",param2);
                sqlmap.add(map);
            }

            if(sqlmap!=null&&sqlmap.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(null,sqlmap);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }

        apidatas.put("flag", flag);
        apidatas.put("mess", mess);

        return apidatas;
    }
    /**
     * 科室 资产管理员个人以及责任人  盘点
     * @param params
     * @param user
     * @return
     */
    public  Map<String, Object> IssueKsDiscovery(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        boolean flag = true;
        String mess = "";
        String uuid = UUID.randomUUID().toString();//本次任务的 一个标识
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        try{
            String pp=(String) weaver.general.Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String) weaver.general.Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String) weaver.general.Util.null2String((String)params.get("sblx")) ;//设备类型
            int rwid= weaver.general.Util.getIntValue((String)params.get("rwid"),-1) ;//部门盘点任务ID
            String notpd=Util.null2String((String)params.get("notpd"));//不需要盘点资产

            log.writeLog("begin---pp>"+pp);
            log.writeLog("begin---ggxh>"+ggxh);
            log.writeLog("begin---sblx>"+sblx);
            log.writeLog("begin---rwid>"+rwid);
            log.writeLog("begin---notpd>"+notpd);

            String sqlwhere =" 1=1 ";
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(notpd)){
                if(notpd.endsWith(",")){
                    notpd=notpd.substring(0,notpd.length()-1);
                }
                sqlwhere=sqlwhere+" and a.id not in ("+notpd+")";
            }

            uf_kszcpdrwBaseService uf_kszcpdrwBaseService=new uf_kszcpdrwBaseService();
            RecordSet re=new RecordSet();
            String countSql=" select   a.syks,count(1) counts from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_kszcpdrw a1,uf_grzcpdjl b1 " +
                    " where a1.id="+rwid+" and a1.id=b1.szkspdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=1 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" group by  a.syks "	;
            log.writeLog(countSql);
            //开始更新  个人资产池里面的数据
            List<Map<String,Object>> sqlmap=new ArrayList<>();
            Map<String,Object> map=null;
            re.execute(countSql);
            while(re.next()){
                String dybmmodel=Util.null2String(re.getString("syks")).trim() ;
                Object[] param2=new Object[3];
                String fromSql="select id from (select  b1.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,  uf_kszcpdrw a1,uf_grzcpdjl b1 " +
                        " where a1.id="+rwid+" and a1.id=b1.szkspdrw and isnull(b1.sfyx,-1) in (0,-1) and b1.lypdfs=1 and isnull(b1.sfkspd,-1) in (-1,1) and b1.swzcid=a.id  and  "+sqlwhere+" and b1.zrks='"+dybmmodel+"' and isnull(b1.zrks,0)>0 ) a1 "	;
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                log.writeLog("IssueDepSysadminDiscovery-->"+fromSql);
                String sql12="update uf_grzcpdjl  set sfkspd=?,lypdfs=?,sjly=? where id in ("+fromSql+")";
                param2[0]=0;
                param2[1]=2;
                param2[1]=rwid;
                //getSwSysadmin
                map=new HashMap<>();
                map.put("sql",sql12);
                map.put("params",param2);
                sqlmap.add(map);
            }

            if(sqlmap!=null&&sqlmap.size()>0){
                mess=uf_kszcpdrwBaseService.getObjMapList(null,sqlmap);
                if(!"".equals(mess)){
                    throw new Exception(mess);
                }
            }
        }catch(Exception e){
            flag=false;
            mess=e.getMessage();
        }

        apidatas.put("flag", flag);
        apidatas.put("mess", mess);

        return apidatas;
    }
}
